
/**
 * @fileoverview Simple implementation of javax.servlet.http.HttpServletRequest.
 * @link http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
 * @link https://developers.google.com/closure/compiler/docs/js-for-compiler
 */



/**
 * Simple implementation of javax.servlet.http.HttpServletRequest.
 * @constructor
 * @extends {net.ServletRequest} net.ServletRequest
 */
net.HttpServletRequest = function() {
  net.ServletRequest.apply(this, arguments);

  /**
   * Returns the query string that is contained in the request URL after the
   *     path.
   * @return {string} Returns the query string that is contained in the request
   *     URL after the path.
   */
  this.getQueryString = function() {
    return location.search && location.search.substr(1);
  };

  /**
   * Returns the portion of the request URI that indicates the context of the
   * request.
   * @return {string} Returns current context path.
   */
  this.getContextPath = function() {
    if (!net.HttpServletRequest.contextPath_) {
      /** @type {Element} */ var a = dom.createElement('A');
      a['href'] = net.HttpServletRequest.scriptPath_;

      /** @type {string} */ var contextPath = (a['pathname'].replace(
          net.HttpServletRequest.scriptPath_.replace(/(\.+\/)+/, ''), ''));

      contextPath = contextPath.replace(
          location.protocol + '//' + location.host, '');

      net.HttpServletRequest.contextPath_ = contextPath;
    }
    return net.HttpServletRequest.contextPath_;
  };
};

(function() {
  /** @type {NodeList} */
  var scripts = dom.getElementsByTagName(dom.document, 'SCRIPT');
  net.HttpServletRequest.scriptPath_ =
      scripts[scripts.length - 1].getAttribute('src');
})();
